<?php $auth=0; ?>
<?php include 'lib/includes.php'; ?>
<?php include 'partials/header_menu.php'; ?>
<?php 
if(isset($_GET['delete']))
{
	$id=$db->quote($_GET['delete']);
	$db->query("delete from medicament where medicamentId=$id");
}
$select=$db->query('select medicamentId,medicamentNom,medicamentPrix,societeNom from medicament inner join societe on medicament.societeId=societe.societeId');
$meds=$select->fetchAll();
/**
*suppression
**/
?>

<br>
<br>
<h3>La liste des médicaments</h3>
<br>
<p>&nbsp;&nbsp;<a href="drug_edit.php" class="btn btn-success">ajouter un nouveau médicament  <span  class="glyphicon glyphicon-plus"></span></a><p>
<center>
<div id="med" style="width: 100%; height: 380px;"></div>
	<script>var i=0;</script>
	<?php  foreach($meds as $med){ 
	//echo json_encode($soc); 
	?>
	<script>
	var sup='<a href="drug_edit.php?id=<?php echo($med['medicamentId']); ?>" class="glyphicon glyphicon-edit">&nbsp;editer</a>&nbsp;&nbsp;<a href="drug.php?delete=<?php echo($med['medicamentId']); ?>" class="glyphicon glyphicon-remove" onclick="">&nbsp;supprimer</a>';
	i++;
	$('#med').w2grid({
    name: 'grid',
    header: 'Liste des medicaments',
    show: {
        toolbar: true,
        footer: true
    },
    columns: [
        { field: 'recid', caption: 'Num', size: '30px', sortable: true, attr: 'align=center' },
        { field: 'ID', caption: 'ID du médicament', size: '20%', sortable: true, resizable: true },
		{ field: 'nmed', caption: 'Nom du médicament', size: '30%', sortable: true, resizable: true },
        { field: 'pmed', caption: 'Prix dumédicament', size: '30%', resizable: true },
        { field: 'noms', caption: 'Nom du société', size: '30%', resizable: true },
		{ field: 'link', caption: 'Action', size: '30%', resizable: true },
    ],
    searches: [
        { field: 'ID', caption: 'ID du médicament', type: 'text' },
        { field: 'nmed', caption: 'Nom du médicament', type: 'text' },
        { field: 'pmed', caption: 'Prix dumédicament', type: 'text' },
		{ field: 'noms', caption: 'Nom du société', type: 'text' },
    ],
    sortData: [{ field: 'recid', direction: 'ASC' }]
    });
	w2ui['grid'].add({ recid:  i , ID: <?php echo($med['medicamentId']); ?> , nmed: '<?php echo($med['medicamentNom']); ?>', pmed: '<?php echo($med['medicamentPrix']); ?>', noms: '<?php echo($med['societeNom']); ?>',link:sup });
	</script>
	<?php }?>	
</center>
<br>
<?php include 'partials/footer.php'; ?>
